<template>
    <div>
       <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="产品名称" prop="productName">
    <el-input v-model="ruleForm.productName" size="mini"></el-input>
  </el-form-item>
  <el-form-item label="产品介绍" prop="productDes">
    <el-input type="textarea" v-model="ruleForm.productDes"></el-input>
  </el-form-item>
  <el-form-item label="产品价格" prop="productPrice">
    <el-input type="text" v-model="ruleForm.productPrice"></el-input>
  </el-form-item>
  <el-form-item label="产品数量" prop="quantity">
    <el-input type="text" v-model="ruleForm.quantity"></el-input>
  </el-form-item>
  <el-form-item label="产品分类" prop="productClassify">
    <el-select v-model="ruleForm.productClassify" placeholder="请选择产品类别">
      <el-option label="牛饲料" value="shanghai"></el-option>
      <el-option label="猪饲料" value="beijing"></el-option>
      <el-option label="鱼饲料" value="beijing"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="立即上架" prop="state">
    <el-switch v-model="ruleForm.state"></el-switch>
  </el-form-item>
  <el-form-item label="上传图片" prop="state">
    
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
    </div>
  </template>
  <script>
  // 导入组件
 export default {
    name: 'addGoods',
    data() {
      return {
        ruleForm: {
          productName: '',
          productDes: '',
          productClassify: '',
          productPrice: '',
          quantity: 0,
          state: false,
          },
        rules: {
            productName: [
            { required: true, message: '请输入产品名称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          productClassify: [
            { required: true, message: '请选择产品类别', trigger: 'change' }
          ],
          productPrice: [
            { required: true, message: '请输入产品价格', trigger: 'blur' }
          ],
          quantity: [
            { required: true, message: '请输入产品数量', trigger: 'blur' }
          ]}
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
  </script>
  <style >

  </style>
  